#
# 你还好吗模块
#


import datetime
import random

from rasa_sdk.executor import CollectingDispatcher
from typing import Text, Dict, Any, List

from rasa_sdk import Action, Tracker
from rasa_sdk.events import SlotSet, SessionStarted, UserUtteranceReverted, FollowupAction
from actions import common
import requests
import re
import time


def current_thought(tracker):
    num = tracker.get_slot('thought_3_change_1')
    cur = 'thought_' + str(num)
    text = tracker.get_slot(cur)
    return text


def conversation_rounds(tracker, **type):
    try:
        if common.rediscommon().get(tracker.current_state()['sender_id'] + '-wx-block-module2'):
            r = common.rediscommon()
            userid = tracker.current_state()['sender_id']
            r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
            common.rediscommon().delete(tracker.current_state()['sender_id'] + '-wx-block-module2')
            return []
    except:
        pass
    if 'type' in type:
        if type['type'] == 1:
            userid = tracker.current_state()['sender_id']
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
            x = cursor.fetchone()
            sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                            15] + 1) + ",is_part_know=1 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
            return []

    userid = tracker.current_state()['sender_id']
    conn = common.POOL.connection(shareable=False)
    cursor = conn.cursor()
    cursor.execute(
        "Select * from `user_result` where topic_type=3 and is_end=0 and user_info_id ='" + userid + "' order by create_time desc")
    x = cursor.fetchone()
    if x[18] not in [(), None, ]:
        r = common.rediscommon()
        try:
            temp = float(r.get(userid + 'TempTimeSteame'))
        except:
            temp = 0
        timenow = time.time()
        c = round(timenow - temp, 3)
        if x[18] == 0.001:
            sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=" + str(
                c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        else:
            sql = "update `user_result` set conversation_rounds=" + str(x[15] + 1) + ",response_time=" + str(x[
                                                                                                                 18] + c) + " where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
            common.connectmysql(sql)
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
    else:
        r = common.rediscommon()
        r.set(userid + 'TempTimeSteame', str(time.time()), ex=86400)
        sql = "update `user_result` set conversation_rounds=" + str(x[
                                                                        15] + 1) + ",response_time=0.000 where `user_info_id` ='" + userid + "' and `is_end` = 0 and `topic_type` =3 order by create_time desc limit 1;"
        common.connectmysql(sql)
    return []


class part8_1_1_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_1_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_info` where `id` = '" + userid + "';")
            x = cursor.fetchone()
            nickname = x[1]
            names = x[2]
            if nickname is None:
                nickname = ''
            if names is None:
                names = ''
            test_batch = str(x[35])
            sql = "insert into `user_result`(`id`,`user_info_id`,`topic_type`,`name`,`conversation_rounds`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + userid + "',3,'" + names + "',0,'" + nickname + "'," + str(
                x[35]) + ");"
            common.connectmysql(sql)
            cursor.close()
            conn.close()
            conn = common.POOL.connection(shareable=False)
            cursor = conn.cursor()
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            sql = "insert into `user_tools_response` (`id`,`user_info_id`,`user_result_id`,`name`,`use_tools`,`nick_name`,`test_batch`) values('" + common.getuid() + "','" + \
                  userid + "','" + x[0] + "','" + names + "','你还好吗','" + nickname + "'," + test_batch  + ");"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x006')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你知道我最常被问到的问题是什么吗?', buttons=[
            {'payload': '/button_part8_1_2_choose_1', 'title': '你是人类吗？', 'life': 1},
            {'payload': '/button_part8_1_2_choose_2', 'title': '想不到哎，快告诉我！', 'life': 1},
            {'payload': '/button_part8_1_2_choose_3', 'title': '你是单身吗？', 'life': 1}, ],
                                 json_message={"module_type": 2, 'word_module_type': 4})
        return []


class part8_1_2_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_2_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我确实经常被问到这个问题(顺便说一下，答案是否定的)。')
        dispatcher.utter_message(text='但这实际上不是我被问得最多的问题……', buttons=[
            {'payload': '/button_part8_1_2_choose_2', 'title': '那是什么呢？', 'life': 1}, ])
        return []


class part8_1_2_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_2_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是“我会感觉好点吗?”')
        dispatcher.utter_message(text='来自各行各业、面临各种挑战的人都想知道这个问题他们想知道他们是否会很快感觉好起来，或者他们的症状是否会消失',
                                 image='https://obs-e912.obs.cn-east-2.myhuaweicloud.com/zy_xm/image/rasa_photo_2021_08_16/add/feel_better.png',
                                 buttons=[
                                     {'payload': '/button_part8_1_3_choose_1', 'title': '有道理？', 'life': 1},
                                     {'payload': '/button_part8_1_3_choose_2', 'title': '我会感觉好点吗?？', 'life': 1}, ])
        return []


class part8_1_2_choose_3(Action):
    def name(self) -> Text:
        return "action_part8_1_2_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我和我的用户😇保持着忠诚的关系。')
        dispatcher.utter_message(text='但这实际上不是我被问得最多的问题……', buttons=[
            {'payload': '/button_part8_1_2_choose_2', 'title': '那是什么呢？', 'life': 1}, ])
        return []


class part8_1_3_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_3_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你想听我给你讲个故事来解释我的意思。还是直接切入临床上的内容？不管哪种都可以哦~', buttons=[
            {'payload': '/button_part8_1_4_choose_1', 'title': '我想听故事', 'life': 1},
            {'payload': '/button_part8_1_4_choose_2', 'title': '直接讲临床上的内容', 'life': 1}, ])
        return []


class part8_1_3_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_3_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='要回答你的问题，我得先解释一些关于心理健康的事情。')
        dispatcher.utter_message(text='我给你讲个故事来说解释一下吧!', buttons=[
            {'payload': '/button_part8_1_4_choose_1', 'title': '好的', 'life': 1}, ])
        return []


class part8_1_4_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_4_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我的同事老贾一直在对抗细菌带来的焦虑和恐惧', buttons=[
            {'payload': '/button_part8_1_5_choose_1', 'title': '听起来好难受啊', 'life': 1}, ])
        return []


class part8_1_4_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_4_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='好的，你知道冬天的日子很冷，很短，常常是灰蒙蒙的，充满了坏天气。', buttons=[
            {'payload': '/button_part8_1_5_choose_2', 'title': '没错', 'life': 1}, ])
        return []


class part8_1_5_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_5_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='是的,很难受。她一遍又一遍地洗手。以至于她的皮肤变得粗糙，疼痛难忍。', buttons=[
            {'payload': '/button_part8_1_6_choose_1', 'title': '我的天呐', 'life': 1},
            {'payload': '/button_part8_1_6_choose_1', 'title': '听着好疼啊……', 'life': 1}, ])
        return []


class part8_1_5_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_5_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='而春天则很少有这样的日子，对吧?夏天呢，更少了', buttons=[
            {'payload': '/button_part8_1_6_choose_2', 'title': '嗯嗯，的确', 'life': 1},
            {'payload': '/button_part8_1_6_choose_2', 'title': '好像是……', 'life': 1}, ])
        return []


class part8_1_6_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_6_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='大约一年前，她开始寻求帮助。她开始去接受治疗，学习认知行为治疗的技巧，和我们一直在练习的类似', buttons=[
            {'payload': '/button_part8_1_7_choose_1', 'title': '她好棒啊', 'life': 1}, ])
        return []


class part8_1_6_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_6_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='你可能希望你能把你的生活变成一个无尽的夏天。但是，坎坷和下雨天是任何人类情感景观的自然特征。不幸的是，这是无法避免的……', buttons=[
            {'payload': '/button_part8_1_7_choose_2', 'title': '的确', 'life': 1}, ])
        return []


class part8_1_7_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_7_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='我也这么认为! 她完全减少了洗手的次数', buttons=[
            {'payload': '/button_part8_1_8_choose_1', 'title': '哇，真好~', 'life': 1}, ])
        return []


class part8_1_7_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_7_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='不过，通过学习，你会培养出对抗恶劣天气的技能。')
        dispatcher.utter_message(text='CBT训练就像一件温暖的外套和一把雨伞CBT培训就像这种日子里的一件温暖的外套和雨伞', buttons=[
            {'payload': '/button_part8_1_8_choose_2', 'title': '我明白了', 'life': 1},
            {'payload': '/button_part8_1_8_choose_2', 'title': '有意思……', 'life': 1}, ])
        return []


class part8_1_8_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_8_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='没错。现在，她有时还是会在不需要洗手的时候洗手。')
        dispatcher.utter_message(text='但这种情况不常发生，而且冲动一旦出现，也不那么强烈了', buttons=[
            {'payload': '/button_part8_1_9_choose_1', 'title': '真是太好了', 'life': 1}, ])
        return []


class part8_1_8_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_8_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='所以说到底，这并不是说再也不会有糟糕的一天', buttons=[
            {'payload': '/button_part8_1_9_choose_2', 'title': '不是吗？', 'life': 1},
            {'payload': '/button_part8_1_9_choose_3', 'title': '嗯嗯！', 'life': 1}, ])
        return []


class part8_1_9_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_9_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='如果冲动发作，她可以使用她所学到的工具来控制冲动。')
        dispatcher.utter_message(text='而她的生活也因此开花结果。她现在甚至还喜欢上了陶艺!', buttons=[
            {'payload': '/button_part8_1_10_choose_1', 'title': '真为老贾开心！~', 'life': 1}, ])
        return []


class part8_1_9_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_9_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='不完全是。')
        dispatcher.utter_message(text='许多人在使用认知行为疗法后感觉好多了。但经历艰难的日子和感到焦虑仍然是正常人类生活中的一部分', buttons=[
            {'payload': '/button_part8_1_10_choose_2', 'title': '有道理', 'life': 1}, ])
        return []


class part8_1_9_choose_3(Action):
    def name(self) -> Text:
        return "action_part8_1_9_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='许多人在使用认知行为疗法后感觉好多了。但艰难度日和难过焦虑仍然是正常人类生活的一部分', buttons=[
            {'payload': '/button_part8_1_10_choose_2', 'title': '的确', 'life': 1}, ])
        return []


class part8_1_10_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_10_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='所以，当我们说某人感觉好了，并不是说他们再也不会有糟糕的一天或焦虑的时刻了', buttons=[
            {'payload': '/button_part8_1_11_choose_1', 'title': '有道理', 'life': 1}, ])
        return []


class part8_1_10_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_10_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='通过学习和实践CBT工具，你的症状会慢慢缓解', buttons=[
            {'payload': '/button_part8_1_11_choose_2', 'title': '太好啦', 'life': 1}, ])
        return []


class part8_1_11_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_11_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='像老贾一样，正在 "变好 "的人拥有处理这些坏日子的技能，因此它们不那么严重，也会渐渐变得不那么频繁。', buttons=[
            {'payload': '/button_part8_1_12_choose_1', 'title': '我还是没明白你的意思', 'life': 1},
            {'payload': '/button_part8_1_8_choose_2', 'title': '我明白啦', 'life': 1}, ])
        return []


class part8_1_11_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_11_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='这样，你就可以建立并维持更有意义的生活质量', buttons=[
            {'payload': '/button_part8_1_12_choose_2', 'title': '嗯嗯~真不错', 'life': 1}, ])
        return []


class part8_1_12_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_12_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='另一种说法是借用大自然的天气来比喻......')
        dispatcher.utter_message(text='冬天的日子很冷，很短，常常是灰蒙蒙的，充满了坏天气。', buttons=[
            {'payload': '/button_part8_1_5_choose_2', 'title': '没错', 'life': 1}, ])
        return []


class part8_1_12_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_12_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        dispatcher.utter_message(text='谢谢你和我谈论这个非常重要的话题。你觉得今天的课怎么样?', buttons=[
            {'payload': '/button_part8_1_13_choose_1', 'title': '好', 'life': 1},
            {'payload': '/button_part8_1_13_choose_2', 'title': '不好', 'life': 1}, ])
        return []


class part8_1_13_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_13_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            if tracker.current_state()['events'][-2]['text'] == '/button_part8_1_13_choose_1':
                sql = "update user_tools_response set evaluation_better_is_relative='好' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x050')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='耶!很高兴你喜欢!你现在还有什么想谈的吗?', buttons=[
            {'payload': '/button_part8_1_14_choose_1', 'title': '没有', 'life': 1},
            {'payload': '/button_part8_1_14_choose_2', 'title': '有~再跟我聊聊吧', 'life': 1}, ])
        return []


class part8_1_13_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_13_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            cursor.execute(
                "Select * from `user_result` where `user_info_id` = '" + userid + "' and `is_end` = 0 and `topic_type` = 3 order by create_time desc limit 1;")
            x = cursor.fetchone()
            result_id = x[0]
            if tracker.current_state()['events'][-2]['text'] == '/button_part8_1_13_choose_2':
                sql = "update user_tools_response set evaluation_better_is_relative='不好' where `user_info_id` ='" + userid + "' and `user_result_id` = '" + result_id + "' limit 1;"
            common.connectmysql(sql)
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x050')
            return [UserUtteranceReverted()]
        finally:
            cursor.close()
            conn.close()
        dispatcher.utter_message(text='谢谢你跟我分享你对这节课的意见。我会让我的创造者知道，这样他们就能让我变得更好。')
        dispatcher.utter_message(text='你现在还有什么想谈的吗?', buttons=[
            {'payload': '/button_part8_1_14_choose_3', 'title': '嗯嗯！', 'life': 1},
            {'payload': '/button_part8_1_14_choose_4', 'title': '没有', 'life': 1}, ])
        return []


class part8_1_14_choose_1(Action):
    def name(self) -> Text:
        return "action_part8_1_14_choose_1"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='好吧，你今天非常努力非常棒哦~')
        dispatcher.utter_message(text='你已完成当天的实验流程')
        dispatcher.utter_message(text='一会儿聊！', buttons=[
            {'payload': '/greet', 'title': 'bye', 'life': 1}, ])
        return []


class part8_1_14_choose_2(Action):
    def name(self) -> Text:
        return "action_part8_1_14_choose_2"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        global user_days
        conversation_rounds(tracker)
        a = ['/button_part2_1_choose_1']
        b = ['/into_grateful_thing_input_1', '/button_part5_1_1_choose_1', '/button_part13_1_1_choose_1',
             '/button_build_power', '/button_part11_1_1_choose_1']
        c = ['/button_part9_1_1_choose_1']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            userid = tracker.current_state()['sender_id']
            cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
            t = cursor.fetchone()
            user_days = t[27]
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x0204')
        finally:
            cursor.close()
            conn.close()
        if user_days == -1 or user_days >= 7:
            dispatcher.utter_message(text='你想试一试其他的功能吗？',
                                     buttons=[{"payload": random.choice(a + b + c), "title": "好的", "life": 1}])
        else:

            dispatcher.utter_message(text='你想试一试其他的功能吗？',
                                     buttons=[{"payload": random.choice(a + b), "title": "好的", "life": 1}])
        return []


class part8_1_14_choose_3(Action):
    def name(self) -> Text:
        return "action_part8_1_14_choose_3"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        global user_days
        a = ['/button_part2_1_choose_1']
        b = ['/into_grateful_thing_input_1', '/button_part5_1_1_choose_1', '/button_part13_1_1_choose_1',
             '/button_build_power', '/button_part11_1_1_choose_1']
        c = ['/button_part9_1_1_choose_1']
        conn = common.POOL.connection(shareable=False)
        cursor = conn.cursor()
        try:
            userid = tracker.current_state()['sender_id']
            cursor.execute("Select * from `user_info` where `id` = '" + userid + "'")
            t = cursor.fetchone()
            user_days = t[27]
        except:
            dispatcher.utter_message(text='机器人错误 错误码0x0204')
        finally:
            cursor.close()
            conn.close()
        if user_days == -1 or user_days >= 7:
            dispatcher.utter_message(text='你想试一试其他的功能吗？',
                                     buttons=[{"payload": random.choice(a + b + c), "title": "好的", "life": 1}])
        else:
            dispatcher.utter_message(text='你想试一试其他的功能吗？',
                                     buttons=[{"payload": random.choice(a + b), "title": "好的", "life": 1}])
        return []


class part8_1_14_choose_4(Action):
    def name(self) -> Text:
        return "action_part8_1_14_choose_4"

    async def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        conversation_rounds(tracker)
        userid = tracker.current_state()['sender_id']
        sql = "update `user_result` set `is_end` = 1,end_time=now() where `user_info_id`='" + userid + "' and `topic_type` = 3 and `is_end` = 0 order by create_time desc limit 1;"
        common.connectmysql(sql)
        dispatcher.utter_message(text='好吧，你今天非常努力非常棒哦~,,你已完成当天的实验流程,一会儿聊!', buttons=[
            {'payload': '/greet', 'title': 'bye', 'life': 1}, ])
        return []
